﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using SMIS.Entities;
using SMIS.Dals;

namespace SMIS
{
    public partial class FormDepart : Form
    {
        public FormDepart()
        {
            InitializeComponent();
        }

        private void FormDepart_Load(object sender, EventArgs e)
        {
            List<Depart> jobs = Dal4Depart.SearchAllDeparts();
            gvDeparts.DataSource = jobs;
        }

        private void button3_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        //【高月 2013-4-7-211634】修改部门信息按钮事件
        private void button1_Click(object sender, EventArgs e)
        {
            if (gvDeparts.SelectedRows.Count == 0)
                MessageBox.Show("请选择要修改的行!", "提示");
            else
            {
                Depart depart = gvDeparts.SelectedRows[0].DataBoundItem as Depart;
                ModifyDepart modifyDepart = new ModifyDepart();
                modifyDepart.MdfName = depart.Name;
                modifyDepart.MdfLeader = depart.Leader;
                modifyDepart.MdfRemark = depart.Remark;
                modifyDepart.MdfID = depart.ID;
                modifyDepart.ShowDialog();
            }
        }

        //【高月 2013-4-7-220857】删除部门信息按钮事件
        private void button2_Click(object sender, EventArgs e)
        {
            if (gvDeparts.SelectedRows.Count == 0)
                MessageBox.Show("请选择要删除的行！", "提示");
            else
            {
                Depart depart = gvDeparts.SelectedRows[0].DataBoundItem as Depart;
                if (MessageBox.Show("确定要删除此部门信息？", "确认提示", MessageBoxButtons.OKCancel,
                        MessageBoxIcon.Question) == DialogResult.OK)
                {
                    if (Dal4Depart.DeleteSelectedDepart(depart) == true)
                        MessageBox.Show("恭喜你删除部门信息成功！", "提示");
                    else
                        MessageBox.Show("删除部门信息失败，请先删除与此部门相关的员工", "提示");
                }
            }
        }
    }
}
